package cn.wolfcode.service.impl;

import cn.wolfcode.domain.Announcement;
import cn.wolfcode.mapper.AnnouncementMapper;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IAnnouncementService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AnnouncementServiceImpl implements IAnnouncementService {

    @Autowired
    private AnnouncementMapper announcementMapper;


    @Override
    public void save(Announcement announcement) {
        announcementMapper.insert(announcement);
    }

    @Override
    public void delete(Long id) {
        announcementMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void update(Announcement announcement) {
        announcementMapper.updateByPrimaryKey(announcement);
    }

    @Override
    public Announcement get(Long id) {
        return announcementMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Announcement> listAll() {
        return announcementMapper.selectAll();
    }

    @Override
    public int getCount(Long id) {
        return announcementMapper.getCount(id);
    }

    @Override
    public List<Announcement> selectNoRead(Long id) {
        return announcementMapper.selectNoRead(id);
    }

    @Override
    public void changeIStatus(Long id,boolean status) {
        announcementMapper.changeIStatus(id,status);
    }

    @Override
    public boolean getStatus(Long eId, Long aId) {
        return announcementMapper.getStatus(eId,aId);
    }

    @Override
    public Announcement getOneById(Long aId) {
        return announcementMapper.getOneById(aId);
    }

    @Override
    public void changeStatus(Long eId, Long aId) {
        announcementMapper.changeStatus(eId,aId);
    }

    @Override
    public PageInfo<Announcement> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize()); //对下一句sql进行自动分页
        List<Announcement> announcements = announcementMapper.selectForList(qo); //里面不需要自己写limit
        return new PageInfo<Announcement>(announcements);
    }
}
